// 生成分页控件
function generatePagination(currentPage, totalPages) {
  let paginationHtml = '';
  
  // 上一页按钮
  if (currentPage > 1) {
    paginationHtml += `<li><a href="javascript:void(0)" onclick="changePage(${currentPage-1})" aria-label="Previous"><span aria-hidden="true">«</span></a></li>`;
  } else {
    paginationHtml += `<li class="disabled"><a href="javascript:void(0)" aria-label="Previous"><span aria-hidden="true">«</span></a></li>`;
  }
  
  // 计算显示的页码范围
  let startPage = Math.max(1, currentPage - 2);
  let endPage = Math.min(totalPages, currentPage + 2);
  
  // 如果开始页大于1，添加第一页和省略号
  if (startPage > 1) {
    paginationHtml += `<li><a href="javascript:void(0)" onclick="changePage(1)">1</a></li>`;
    if (startPage > 2) {
      paginationHtml += `<li class="disabled"><a href="javascript:void(0)">...</a></li>`;
    }
  }
  
  // 生成页码
  for (let i = startPage; i <= endPage; i++) {
    if (i === currentPage) {
      paginationHtml += `<li class="active"><a href="javascript:void(0)">${i} <span class="sr-only">(current)</span></a></li>`;
    } else {
      paginationHtml += `<li><a href="javascript:void(0)" onclick="changePage(${i})">${i}</a></li>`;
    }
  }
  
  // 如果结束页小于总页数，添加省略号和最后一页
  if (endPage < totalPages) {
    if (endPage < totalPages - 1) {
      paginationHtml += `<li class="disabled"><a href="javascript:void(0)">...</a></li>`;
    }
    paginationHtml += `<li><a href="javascript:void(0)" onclick="changePage(${totalPages})">${totalPages}</a></li>`;
  }
  
  // 下一页按钮
  if (currentPage < totalPages) {
    paginationHtml += `<li><a href="javascript:void(0)" onclick="changePage(${currentPage+1})" aria-label="Next"><span aria-hidden="true">»</span></a></li>`;
  } else {
    paginationHtml += `<li class="disabled"><a href="javascript:void(0)" aria-label="Next"><span aria-hidden="true">»</span></a></li>`;
  }
  
  $("#pagination").html(paginationHtml);
}